﻿using System.Collections.Generic;
using WebSite.ViewModels.Fields;

namespace WebSite.ViewModels.DetailsViewModels
{
    public abstract class AttributeHolderDetailsViewModel : DetailsViewModel
    {
        public Dictionary<string, string> Attributes { get; set; }

        protected AttributeHolderDetailsViewModel(string title) 
            : base(title)
        {
        }

        protected override IEnumerable<IField> GetGeralFields()
        {
            List<IField> result = new List<IField>();

            if (Attributes != null)
            {
                foreach (var attribute in Attributes)
                {
                    string caption = attribute.Key.Substring(1).Replace('_', ' ');
                    result.Add(new LabelField(caption, attribute.Key, attribute.Value));
                }
            }

            result.AddRange(base.GetGeralFields());
            return result;
        }
    }
}